home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Chess++ ƒ / CChessPieces ƒ / CBishop.cp next >
Text File  |  1993-05-26  |  1KB  |  67 lines

  1. ////////////
  2. //
  3. //    CBishop.cp
  4. //
  5. //    Abstract Chess Piece methods.
  6. //
  7. //    Copyright © 1993 Steven J. Bushell. All rights reserved.
  8. //
  9. ////////////
  10.  
  11. #include <stdlib.h>
  12.  
  13. #include "CChessBoard.h"
  14. #include "CChessPiece.h"
  15. #include "CBishop.h"
  16.  
  17. extern    CIconHandle    gWhiteBishopCicnHandle;
  18. extern    CIconHandle    gBlackBishopCicnHandle;
  19.  
  20. void CBishop::IBishop(Boolean aColor)
  21. {
  22.     inherited::IChessPiece(aColor);
  23.     itsValue = 0x0300;
  24. }
  25.  
  26. void CBishop::Draw(short rank, short file)
  27. {
  28.     CIconHandle cicnHandle;
  29.     Rect aRect;
  30.     short rankQD = (rank - 1) << 5, fileQD = (file - 1) << 5;
  31.     
  32.     if (itsColor == White)
  33.         cicnHandle = gWhiteBishopCicnHandle;
  34.     else
  35.         cicnHandle = gBlackBishopCicnHandle;
  36.  
  37.     aRect.left = rankQD;
  38.     aRect.right = rankQD+32;
  39.     aRect.top = fileQD;
  40.     aRect.bottom = fileQD+32;
  41.     PlotCIcon(&aRect,cicnHandle);
  42. }
  43.  
  44. CIconHandle    CBishop::GetCicnHandle(void)
  45. {
  46.     return gWhiteBishopCicnHandle;
  47. }
  48.  
  49. Boolean    CBishop::IsValidMove(CChessBoard *aBoard, short newRank, short newFile)
  50. {
  51.     short    oldRank = aBoard->firstClickRank, oldFile = aBoard->firstClickFile;
  52.     register i,j;
  53.     short iDelta,rankDelta = newRank-oldRank,fileDelta = newFile-oldFile;
  54.     
  55.     if (abs(rankDelta) == abs(fileDelta))
  56.     {
  57.         rankDelta = abs(rankDelta)/rankDelta;
  58.         fileDelta = abs(fileDelta)/fileDelta;
  59.         for(i=oldRank+rankDelta,j=oldFile+fileDelta;i!=newRank;
  60.             i+=rankDelta,j+=fileDelta)
  61.                 if (aBoard->theBoard[i][j])
  62.                     return false;
  63.         return true;
  64.     }
  65.  
  66.     return false;    
  67. }